package org.rendao.question.query
{
	import mx.collections.ArrayCollection;
	
	import org.rendao.entity.FirstIndex;
	import org.rendao.entity.QuestionCriteria;
	import org.rendao.entity.SecondIndex;
	import org.rendao.entity.UserDetail;
	import org.rendao.service.FirstIndexService;
	import org.rendao.service.QuestionService;
	import org.rendao.service.SecondIndexService;
	import org.rendao.service.UserService;

	public class QuestionQueryViewPM
	{
		public var dm:QuestionQueryViewDM;
		
		public function getFirstIndexList():void {
			var onGet:Function = function(list:Array):void {
				var result:ArrayCollection = new ArrayCollection(list);
				var defaultItem:FirstIndex = new FirstIndex();
				defaultItem.name = dm.SELECT_ALL_LABEL;
				result.addItemAt(defaultItem, 0);
				dm.firstIndexList = result;
			};
			FirstIndexService.instance.getAll(onGet);
		}
		
		public function getDefaultSecondIndexList():void {
			var defaultItem:SecondIndex = new SecondIndex();
			defaultItem.name = dm.SELECT_ALL_LABEL;
			dm.secondIndexList = new ArrayCollection([defaultItem]);
		}
		
		public function getSecondIndexList(firstIndexId:String):void {
			var onGet:Function = function(list:Array):void {
				var result:ArrayCollection = new ArrayCollection(list);
				var defaultItem:SecondIndex = new SecondIndex();
				defaultItem.name = dm.SELECT_ALL_LABEL;
				result.addItemAt(defaultItem, 0);
				dm.secondIndexList = result;
			};
			SecondIndexService.instance.getByFirstIndex(firstIndexId, onGet);
		}
		
		public function getUserList():void {
			var onGet:Function = function(list:Array):void {
				var result:ArrayCollection = new ArrayCollection(list);
				var defaultItem:UserDetail = new UserDetail();
				defaultItem.displayName = dm.SELECT_ALL_LABEL;
				result.addItemAt(defaultItem, 0);
				dm.userList = result;
			};
			UserService.instance.getAllUser(onGet);
		}
		
		public function search(criteria:QuestionCriteria):void {
			var onSearch:Function = function(list:Array):void {
				dm.questionList = new ArrayCollection(list);
			};
			QuestionService.instance.search(criteria, onSearch);
		}
	}
}